<%@ page import="com.cpkf.yyjd.crawler.config.*"%>
<%@ page import="com.cpkf.yyjd.crawler.config.*"%>
<%@ page import="com.cpkf.yyjd.crawler.config.*"%>
<%@ page import="com.cpkf.yyjd.crawler.app.task.entity.CrawlTask"%>
<%@ page import="java.util.StringTokenizer"%>

<html>
<head>
<title>新创建的任务</title>
</head>
<%@ page contentType="text/html;charset=utf-8"%>
<body>
<h3>任务信息</h3>
<p>
<%

String name = request.getParameter("name");
String seed = request.getParameter("seed");
String deep = request.getParameter("deep");
String match = request.getParameter("match");
String filter = request.getParameter("filter");
String match_list = request.getParameter("match_list");
String filter_list = request.getParameter("filter_list");


String connectiontimeout = request.getParameter("connectiontimeout");
String sockettimeout = request.getParameter("sockettimeout");
String filepath = request.getParameter("filepath");
String startHardwareAdjust = request.getParameter("startHardwareAdjust");
String interval = request.getParameter("interval");

String nodeCount = request.getParameter("nodeCount");
String scalable = request.getParameter("scalable");
String textfield = request.getParameter("textfield");

String testSeeds = request.getParameter("seed_list");

String hiddenSeeds = request.getParameter("hiddenSeeds");

String hiddenMatch = request.getParameter("hiddenMatch");
String hiddenFilter = request.getParameter("hiddenFilter");

String extractorType = request.getParameter("extractorType");
String intelligentCookieType = request.getParameter("intelligentCookieType");
String needImgs = request.getParameter("needImgs");
String startUpdate = request.getParameter("startUpdate");

String matchCurrent = "";
String filterCurrent = "";

if(null == filter||"".equalsIgnoreCase(filter.trim()))
{
   filterCurrent = filter_list;
}

if(null == match||"".equalsIgnoreCase(match.trim()))
{
   matchCurrent = match_list;
}


//判断名字
if(null==nodeCount)
{
System.out.println("nodeCount is null");
}


if(null == name)
{
response.sendRedirect("newtask.jsp");
}
else{
//判断名字
if(name.length()<3)
{
out.println("名字输入长度不能小于3");
}

if(name.length()>30)
{
out.println("名字输入长度不能大于30");
}



else
{
name = new String(name.getBytes("ISO-8859-1"),"GBK");

System.out.println("任务名称:"+name+"<br>");
System.out.println("种子页面:"+seed+"<br>");
System.out.println("深度:"+deep+"<br>");
System.out.println("需要的URL:"+match+"<br>");
System.out.println("被过滤的URL:"+filter+"<br>");

System.out.println("需要的URL_list:"+match_list+"<br>");
System.out.println("被过滤的URL_list:"+filter_list+"<br>");

System.out.println("连接超时时间:"+connectiontimeout+"<br>");
System.out.println("流读取超时时间:"+sockettimeout+"<br>");
System.out.println("本地文件保存路径:"+filepath+"<br>");
System.out.println("是否启动硬件调整:"+startHardwareAdjust+"<br>");
System.out.println("启动节点数:"+nodeCount+"<br>");
System.out.println("scalable:"+scalable+"<br>");
System.out.println("matchCurrent:"+matchCurrent+"<br>");
System.out.println("filterCurrent:"+filterCurrent+"<br>");
System.out.println("textfield:"+textfield+"<br>");
System.out.println("testSeeds:"+testSeeds+"<br>");
System.out.println("hiddenSeeds:"+hiddenSeeds+"<br>");
System.out.println("hiddenMatch:"+hiddenMatch+"<br>");
System.out.println("hiddenFilter:"+hiddenFilter+"<br>");
System.out.println("解析方式:"+extractorType+"<br>");
System.out.println("智能COOKIE方式:"+intelligentCookieType+"<br>");
System.out.println("是否需要保存图片:"+needImgs+"<br>");
System.out.println("是否需要启动更新模块:"+startUpdate+"<br>");


//获取配置
        CrawlConfig crawlConfig = CrawlConfigUtil.getBaseConfig();
//获取解析方式 static  dynamic
        if ("static".equalsIgnoreCase(extractorType)) {
			crawlConfig.setExtractorType(0);
		} else {
			crawlConfig.setExtractorType(1);
		}
        
//加入所有的种子页面
        StringTokenizer seedTokenizer = new StringTokenizer(hiddenSeeds,",");
		int i = 0;
		while(seedTokenizer.hasMoreTokens())
		{
		    String oneSeed = seedTokenizer.nextToken().trim();
            crawlConfig.getUrl().addSeed(oneSeed);
			System.out.println("oneSeed "+i+"="+oneSeed);
			i++;
		}

//选择了匹配项才加入 加入所有的匹配正则
       if(null != hiddenMatch&&!"".equalsIgnoreCase(hiddenMatch.trim()))
       {
            StringTokenizer matchTokenizer = new StringTokenizer(hiddenMatch,",");
		    int j = 0;
		   while(matchTokenizer.hasMoreTokens())
		   {
		    String oneMatch = matchTokenizer.nextToken().trim();
            crawlConfig.getUrl().getExtractor().getAccept().addPatten(oneMatch);
			System.out.println("oneMatch "+j+"="+oneMatch);
			j++;
		    }
            
       }

//选择了过滤项才加入
      if(null != hiddenFilter&&!"".equalsIgnoreCase(hiddenFilter.trim()))
      {
           StringTokenizer filterTokenizer = new StringTokenizer(hiddenFilter,",");
		   int k = 0;
		   while(filterTokenizer.hasMoreTokens())
		   {
		    String oneFilter = filterTokenizer.nextToken().trim();
            crawlConfig.getUrl().getExtractor().getFilter().addPatten(oneFilter);
			System.out.println("oneFilter "+k+"="+oneFilter);
			k++;
		   }
   
      }
//设置网页文件保存路径
       crawlConfig.setFilepath(filepath);
       
//设置是否启动硬件资源调整策略       
		if ("yes".equalsIgnoreCase(startHardwareAdjust)) {
			crawlConfig.setStartHardwareAdjust(1);
		} else {
			crawlConfig.setStartHardwareAdjust(0);
		}
		
//设置是否保存图片
		if ("yes".equalsIgnoreCase(needImgs)) {
			crawlConfig.setNeedImgs(1);
		} else {
			crawlConfig.setNeedImgs(0);
		}
		
//设置是否启动更新模块
		if ("yes".equalsIgnoreCase(startUpdate)) {
			crawlConfig.setStartUpdate(1);
		} else {
			crawlConfig.setStartUpdate(0);
		}
		
		
//设置使用智能COOKIE的方式   
		if ("none".equalsIgnoreCase(intelligentCookieType)) 
		{
			crawlConfig.setIntelligentCookieType(0);
		} 
		else if ("intelligent".equalsIgnoreCase(intelligentCookieType))
		{
			crawlConfig.setIntelligentCookieType(1);
		}
		else
		{
		    crawlConfig.setIntelligentCookieType(2);
		}

//设置种子深度
		try {
			crawlConfig.getUrl().setDepth(new Integer((deep)));
//设置超时时间			
			crawlConfig.getHttp().setConnectiontimeout(
					Long.parseLong(connectiontimeout));
			crawlConfig.getHttp().setSockecttimeout(Long.parseLong(sockettimeout));

		} catch (NumberFormatException numberFormatException) {
			numberFormatException.printStackTrace();
		}


		CrawlConfigUtil.buildConfigFile(crawlConfig,name,interval,nodeCount,scalable);

}
}
%>
<table border="1">
<tr><td>任务名称:</td><td ><%=name %></td></tr>
<tr><td>深度:</td><td ><%=deep %></td></tr>
<tr><td>需要的URL_list:</td><td ><%= match_list%></td></tr>
<tr><td>被过滤的URL_list:</td><td ><%= filter_list%></td></tr>
<tr><td>连接超时时间:</td><td ><%= connectiontimeout%></td></tr>
<tr><td>流读取超时时间:</td><td ><%= sockettimeout%></td></tr>
<tr><td>本地文件保存路径:</td><td ><%= filepath%></td></tr>
<tr><td>是否启动硬件调整:</td><td ><%= startHardwareAdjust%></td></tr>
<tr><td>节点个数:</td><td ><%= nodeCount%></td></tr>
<tr><td>节点不够是否继续启动:</td><td ><%= scalable%></td></tr>
<tr><td>已经选择的种子:</td><td ><%= hiddenSeeds%></td></tr>
<tr><td>需要匹配的正则:</td><td ><%= hiddenMatch%></td></tr>
<tr><td>需要过滤的正则:</td><td ><%= hiddenFilter%></td></tr>
<tr><td>解析方式:</td><td ><%= extractorType%></td></tr>
<tr><td>智能COOKIE方式:</td><td ><%= intelligentCookieType%></td></tr>
<tr><td>是否需要保存图片:</td><td ><%= needImgs%></td></tr>
<tr><td>是否需要启动更新模块:</td><td ><%= startUpdate%></td></tr>
<input class="button" type="button" value="返回" onClick="window.location='<%=request.getContextPath()%>/index.jsp'" />
</body>
</html> 